﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Detail : System.Web.UI.Page
{
    public SanPhamDataSet.SanPhamRow sanpham;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            int loaisanpham =Convert.ToInt32( Request.QueryString["loaisanpham"]);
            MasterPageDetail m = this.Master as MasterPageDetail;
            m.loaisanphamid = loaisanpham;
            int id = Convert.ToInt32(Request.QueryString["id"]);

            SanPhamDataSet spDs = new SanPhamHelper().LoadSanPham(id);
            if (spDs.SanPham.Rows.Count>0)
            {
                sanpham = spDs.SanPham[0];
                if (sanpham.IsAlbumNull()) sanpham.Album = "";
                if (sanpham.IsChungLoaiNull()) sanpham.ChungLoai = "";
                if (sanpham.IsGiaNull()) sanpham.Gia = 0;
                if (sanpham.IsHangSanXuatNull()) sanpham.HangSanXuat = "";
                if (sanpham.IsHinhAnhNull()) sanpham.HinhAnh = "";
                if (sanpham.IsLoaiSanPhamNull()) sanpham.LoaiSanPham = 1;
                if (sanpham.IsNgayDangNull()) sanpham.NgayDang = DateTime.Now;
                if (sanpham.IsSanPhamMoiNull()) sanpham.SanPhamMoi = false;
                if (sanpham.IsTenSanPhamNull()) sanpham.TenSanPham = "";
                if (sanpham.IsThongSoKyThuatNull()) sanpham.ThongSoKyThuat = "";
                if (sanpham.IsThuTuNull()) sanpham.ThuTu = 0;
                if (sanpham.IsTongQuanNull()) sanpham.TongQuan = "";
                LoadAlbum();
            }
            LoadSanPhamCungLoai();
            
        }
    }
    private void LoadAlbum()
    {
        repAlbum.DataSource = new HinhAnhSanPhamHelper().LoadHinhAnhSanPhamTheoSanPham(Convert.ToInt32(Request.QueryString["id"]));
        repAlbum.DataBind();
    }
    private void LoadSanPhamCungLoai()
    {
        int loaisanpham = Convert.ToInt32(Request.QueryString["loaisanpham"]);
        SanPhamDataSet spDs = new SanPhamHelper().LoadSanPhamTheoLoai(1, 8, "NgayDang", "DESC", loaisanpham);

        repSanPhamCungLoai.DataSource = spDs.SanPham;
        repSanPhamCungLoai.DataBind();
    }
}
